package com.eshop.dao.Impl;

import com.eshop.dao.OrderDetailDao;
import com.eshop.model.OrderDetail;
import com.eshop.model.myPojo.CartGoods;

import java.util.List;

public class OrderDetailDaoImpl extends BaseDao implements OrderDetailDao {
    @Override
    public OrderDetail queryOrderDetailByOrderDetailId(int orderDetailId) {
        String sql = "select * from t_orderDetail where odetail_id=?";
        return queryForOne(OrderDetail.class,sql,orderDetailId);
    }

    @Override
    public List<OrderDetail> queryOrderDetailByOrderId(int orderId) {
        String sql = "select * from t_orderDetail where order_id=?";
        return queryForList(OrderDetail.class,sql,orderId);
    }

    @Override
    public void addOrderDetail(int orderId, CartGoods cartGoods) {
        String sql = "INSERT INTO t_orderdetail(`order_id`, `goods_id`, `odetail_name`, `odetail_price`, `odetail_num`, `odetail_pic`) VALUES (?,?,?,?,?,?)";
        update(sql,orderId,cartGoods.getGoods_id(),cartGoods.getGoods_name(),cartGoods.getGoods_discount(),cartGoods.getGoods_num(),cartGoods.getGoods_pic());
    }
}
